package com.photo.system.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.photo.system.common.ErrorCode;
import com.photo.system.exception.BusinessException;
import com.photo.system.mapper.ThingsMapper;
import com.photo.system.model.dto.things.ThingsQueryRequest;
import com.photo.system.model.entity.Things;
import com.photo.system.model.vo.ThingsVO;
import com.photo.system.service.ThingsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xuwenhui
 * @description 针对表【things(摄影作品表)】的数据库操作Service实现
 * @createDate 2024-11-21 21:17:09
 */
@Service
public class ThingsServiceImpl extends ServiceImpl<ThingsMapper, Things> implements ThingsService {

    @Resource
    private ThingsMapper thingsMapper;

    @Override
    public Page<ThingsVO> getQueryByAll(Page<ThingsVO> pageParam, ThingsQueryRequest thingsQueryRequest) {
        if (thingsQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        // 自定义分页查询
        List<ThingsVO> tenantsVOList = thingsMapper.getQueryByAll(pageParam, thingsQueryRequest);
        if (tenantsVOList != null) {
            pageParam.setRecords(tenantsVOList);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }

    @Override
    public Page<ThingsVO> getQueryByMy(Page<ThingsVO> pageParam, ThingsQueryRequest thingsQueryRequest, Long userId) {
        if (thingsQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        // 自定义分页查询
        List<ThingsVO> tenantsVOList = thingsMapper.getQueryByMy(pageParam, thingsQueryRequest, userId);
        if (tenantsVOList != null) {
            pageParam.setRecords(tenantsVOList);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }
}




